<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        Teacher.prototype = {
            skill: '解函数'
        }

        function Teacher() {
            this.name = '张三'
            this.age = 30
        }

        function Student(name) {
            this.name = name
            this.class =  3
        } 

        // 原无隔离公共继承方法
        // Student.prototype = Teacher.prototype

        var t1 = new Teacher()
        console.log(t1)
        console.log(t1.skill)

        var s1 = new Student('李四')
        console.log(s1)
        console.log(s1.skill)
        console.log(s1.age)

        // 通过公共原型继承，我们可以发现以及实现了原型上的继承，但原函数的属性却无法获取，与call/apply的方法正好相反
        // 且修改任一原型上的属性，他们会相互影响

        // 解决方案，通过一个空的构造函数做缓存
        function Buffer() {}
        Buffer.prototype = Teacher.prototype
        var buffer = new Buffer()
        console.log(buffer)

        Student.prototype = buffer

        Student.prototype.skill = '解方程'
        
        var s2 = new Student("王五")
        console.log(s1)
        console.log(s2)
        console.log(t1.skill)
    </script>
</body>
</html>